//
//  ChangePwdViewController.m
//  Item
//
//  Created by 刘炳举 on 12/19/15.
//  Copyright © 2015 Kelly. All rights reserved.
//

#import "ChangePwdViewController.h"

@interface ChangePwdViewController ()
@property (retain, nonatomic) IBOutlet UITextField *oldPwd;
@property (retain, nonatomic) IBOutlet UITextField *newPwd;
@property (retain, nonatomic) IBOutlet UITextField *new_Pwd;


@end

@implementation ChangePwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTitleBar];

    
    // Do any additional setup after loading the view.
}
- (IBAction)VIew_Touch:(id)sender {
        [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
}
- (IBAction)changePwd {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if ([ @"" isEqualToString:_oldPwd.text]|| [ @"" isEqualToString:_newPwd.text] || [ @"" isEqualToString:_oldPwd.text]) {
        [self showAlart:@"password is empty"];
    } else {
        if (![[user objectForKey:@"password"] isEqualToString:_oldPwd.text]) {
            [self showAlart:@"oldPwdWrong"];
        }else{
            if (![_newPwd.text isEqualToString:_new_Pwd.text]) {
                [self showAlart:@"newPwd is Not Equal"];
            }else{
                [user setObject:_newPwd.text forKey:@"password"];
                [self showAlart:@"密码修改成功"];
            }
        }
    }
}

-(void)showAlart:(NSString*)msg
{
    UIAlertController* alart = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alart animated:YES completion:nil];
    UIAlertAction* OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 30,100)];
    label.textColor = [UIColor redColor];
    label.text = msg;
    //[alart addSubview:label ];
    [alart addAction:OKAction];
    
}

-(void)viewDidAppear:(BOOL)animated{
    
}

- (void)initTitleBar {
    [self.navigationItem setTitle:@"修改密码"];
    
    UIBarButtonItem *btnBack = [[UIBarButtonItem alloc]
                                initWithTitle:@"设置"
                                style:UIBarButtonItemStylePlain
                                target:self
                                action:nil];
    self.navigationController.navigationBar.topItem.backBarButtonItem=btnBack;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_oldPwd release];
    [_newPwd release];
    [_new_Pwd release];
    [super dealloc];
}
@end
